home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
GAUGE.ARJ
/
OBGAUGE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-14
|
14KB
|
505 lines
{$N+}
{$R OBGAUGE}
program OBGauge;
uses
WObjects, WinTypes, WinProcs, WinDOS, Strings, Utils;
const
AppName : PChar = 'OBGAUGE';
ids_FSpace = 101; (* Free Disk Space Static Control *)
ids_TSpace = 102; (* Total Disk Space Static Control *)
ids_FMem = 103; (* Free Memory Static Control *)
ids_FRes = 104; (* Free System Resources Static Control *)
ids_Date = 105; (* Date Static Control *)
ids_Time = 106; (* Time Static Control *)
idc_Drives = 107; (* Drive Selection Combo Box *)
idr_DSpace = 108; (* Disk Space Radio Button *)
idr_Memory = 109; (* Memory Radio Button *)
idr_SysRes = 110; (* System Resources Radio Button *)
idr_Time = 111; (* Time Radio Button *)
idr_Date = 112; (* Date Radio Button *)
ids_Icon = 125; (* Icon in window! *)
cm_About = 200;
id_Timer = 1;
tDiskRect : TRect = (left : 125; top : 15; right : 375; bottom : 35);
type
TGaugeApp = object(TApplication)
procedure InitMainWindow; virtual;
end;
PGaugeDialog = ^TGaugeDialog;
TGaugeDialog = object(TDlgWindow)
DrivesAdded : Boolean;
redBrush,
whiteBrush : HBrush;
avDiskRect : TRect;
curChoice,
lastDrive,
curDrive : Integer;
sfSpace : PStatic;
stSpace : PStatic;
sfMemory : PStatic;
sfRes : PStatic;
sfTime : PStatic;
sfDate : PStatic;
lbDrives : PListBox;
rbDSpace : PRadioButton;
rbMemory : PRadioButton;
rbSysRes : PRadioButton;
rbTime : PRadioButton;
rbDate : PRadioButton;
constructor Init(AParent : PWindowsObject; AName : Pchar);
destructor Done; virtual;
function GetClassName : PChar; virtual;
procedure GetWindowClass(var AWndClass : TWndClass); virtual;
procedure WMDestroy(var Msg : TMessage); virtual wm_First + wm_Destroy;
procedure WMCtlClr(var Msg : TMessage); virtual wm_First + wm_CtlColor;
procedure WMTimer(var Msg : TMessage); virtual wm_First + wm_Timer;
procedure CMAbout(var Msg : TMessage);
procedure WMSysCommand(var Msg : TMessage);
virtual wm_First + wm_SysCommand;
procedure SetUpWindow; virtual;
procedure InitControls;
procedure UpdateControls(aDC : HDC);
procedure WMPaint(var Msg : TMessage);
virtual wm_First + wm_Paint;
procedure DrawDrive(aDC : HDC; Rect : TRect);
procedure DrawMemory(aDC : HDC; Rect : TRect);
procedure DrawSysRes(aDC : HDC; Rect : TRect);
procedure DrawTime(aDC : HDC; Rect : TRect);
procedure DrawDate(aDC : HDC; Rect : TRect);
procedure IconPaint(aDC : HDC);
procedure Ok(var Msg : TMessage); virtual id_First + id_Ok;
procedure WMCommand(var Msg : TMessage); virtual wm_First + wm_Command;
procedure idDSpace(var Msg : TMessage); virtual id_First + idr_DSpace;
procedure idMemory(var Msg : TMessage); virtual id_First + idr_Memory;
procedure idSysRes(var Msg : TMessage); virtual id_First + idr_SysRes;
procedure idTime(var Msg : TMessage); virtual id_First + idr_Time;
procedure idDate(var Msg : TMessage); virtual id_First + idr_Date;
end;
constructor TGaugeDialog.Init(AParent : PWindowsObject; AName : Pchar);
begin
TDlgWindow.Init(AParent, AName);
InitControls;
DrivesAdded := False;
curChoice := idr_DSpace;
end;
destructor TGaugeDialog.Done;
begin
DeleteObject(whiteBrush);
DeleteObject(redBrush);
TDlgWindow.Done;
end;
procedure TGaugeDialog.Ok(var Msg : TMessage);
begin
SendMessage(HWindow, wm_SysCommand, sc_Minimize, 0);
end;
procedure TGaugeDialog.WMCommand(var Msg : TMessage);
var
aDC : HDC;
begin
if (Msg.WParam = idc_Drives) and (Msg.LParamHi = lbn_SelChange) then
begin
curDrive := lbDrives^.GetSelIndex;
aDC := GetDC(Msg.Receiver);
UpdateControls(aDC);
ReleaseDC(Msg.Receiver, aDC);
end
else
TWindowsObject.WMCommand(Msg);
end;
function TGaugeDialog.GetClassName : PChar;
begin
GetClassName := AppName;
end;
procedure TGaugeDialog.GetWindowClass(var AWndClass : TWndClass);
begin
TDlgWindow.GetWindowClass(AWndClass);
AWndClass.hIcon := 0;
end;
procedure TGaugeDialog.SetUpWindow;
var
curDir : PChar;
dTotal,
avSpace : LongInt;
Ratio : Single;
theMem : String;
theRes : LongInt;
i : Integer;
hSysMenu : HMenu;
theDC : HDC;
begin
TDlgWindow.SetUpWindow;
hSysMenu := GetSystemMenu(HWindow, False);
AppendMenu(hSysMenu, mf_Separator, 0, Nil);
AppendMenu(hSysMenu, mf_String, cm_About, 'About...');
EnableMenuItem(hSysMenu, 2, mf_byPosition or mf_Grayed);
EnableMenuItem(hSysMenu, 4, mf_byPosition or mf_Grayed);
whiteBrush := CreateSolidBrush(RGB(255, 255, 255));
redBrush := CreateSolidBrush(RGB(255, 0, 0));
SetTimer(HWindow, id_Timer, 5000, Nil);
GetMem(curDir, fsDirectory);
GetCurDir(curDir, 0);
curDrive := Ord(curDir[0]) - 67;
FreeMem(curDir, fsDirectory);
SetInternational;
(* First, determine the available drives, skipping A: & B: *)
lastDrive := GetDriveInfo;
theDC := GetDC(HWindow);
UpdateControls(theDC);
ReleaseDC(HWindow, theDC);
end;
procedure TGaugeDialog.UpdateControls(aDC : HDC);
var
curDir : PChar;
oldBrush : HBrush;
dTotal,
avSpace : LongInt;
Ratio,
temp : Single;
theMem : String;
theRes : LongInt;
i : Integer;
tInt : LongInt;
begin
GetAvail(curDrive, avDrives[curDrive].dTotal, avSpace, ratio);
with tDiskRect do
Rectangle(aDC, left, top, right, bottom);
with avDiskRect do begin
left := tDiskRect.left;
top := tDiskRect.top;
bottom := tDiskRect.bottom;
tInt := tDiskRect.right - tDiskRect.left;
temp := Single(tInt) * Ratio;
right := LongInt(temp) + left;
end;
oldBrush := SelectObject(aDC, redBrush);
with avDiskRect do
Rectangle(aDC, left, top, right, bottom);
theMem := GetFreeMemory;
theRes := GetFreeResources;
if (not DrivesAdded) then begin
DrivesAdded := True;
for i := 0 to lastDrive do
lbDrives^.AddString(avDrives[i].dLetter);
end;
GetMem(curDir, 25);
wvsprintf(curDir, '%lu Mb', avSpace);
sfSpace^.SetText(curDir);
wvsprintf(curDir, '%lu Mb', avDrives[curDrive].dTotal);
stSpace^.SetText(curDir);
StrPCopy(curDir, theMem);
sfMemory^.SetText(curDir);
wvsprintf(curDir, '%2u%% User %2u%% GDI', theRes);
sfRes^.SetText(curDir);
FreeMem(curDir, 25);
GetCurDate(curDir);
sfDate^.SetText(curDir);
FreeMem(curDir, StrLen(curDir) + 1);
GetCurTime(curDir);
sfTime^.SetText(curDir);
FreeMem(curDir, StrLen(curDir) + 1);
lbDrives^.SetSelIndex(curDrive);
end;
procedure TGaugeDialog.DrawDrive(aDC : HDC; Rect : TRect);
var
aRect : TRect;
oldBrush : HBrush;
tInt : LongInt;
temp : Single;
oldMode : Integer;
oldAlign : Word;
avSpace : LongInt;
dRatio : Single;
begin
GetAvail(curDrive, avDrives[curDrive].dTotal, avSpace, dRatio);
with aRect do begin
left := Rect.left;
right := Rect.right;
top := Rect.top;
tInt := Rect.bottom;
temp := Single(tInt) * dRatio;
bottom := LongInt(temp);
end;
oldBrush := SelectObject(aDC, redBrush);
with aRect do
Rectangle(aDC, left, top, right, bottom);
SelectObject(aDC, oldBrush);
oldMode := SetBkMode(aDC, Transparent);
TextOut(aDC, Rect.left + 10, Rect.top + 10, avDrives[curDrive].dLetter,
strlen(avDrives[curDrive].dLetter));
SetBkMode(aDC, oldMode);
end;
procedure TGaugeDialog.DrawMemory(aDC : HDC; Rect : TRect);
var
avMem : PChar;
oldMode : Integer;
begin
GetMem(avMem, 20);
StrPCopy(avMem, GetFreeMemory); (* get memory *)
oldMode := SetBkMode(aDC, Transparent);
DrawText(aDC, avMem, strlen(avMem), Rect, dt_WordBreak);
FreeMem(avMem, 20);
SetBkMode(aDC, oldMode);
end;
procedure TGaugeDialog.DrawSysRes(aDC : HDC; Rect : TRect);
var
lRes : LongInt;
tWord : Word;
avResource : PChar;
oldMode : Integer;
begin
lRes := GetFreeResources; (* get free resources *)
if (LoWord(lRes) < HiWord(lRes)) then
tWord := LoWord(lRes)
else
tWord := HiWord(lRes);
GetMem(avResource, 25);
wvsprintf(avResource, '%2u%% Avail', tWord);
oldMode := SetBkMode(aDC, Transparent);
DrawText(aDC, avResource, strlen(avResource), Rect, dt_WordBreak);
FreeMem(avResource, 25);
SetBkMode(aDC, oldMode);
end;
procedure TGaugeDialog.DrawTime(aDC : HDC; Rect : TRect);
var
theTime : PChar;
oldMode : Integer;
begin
GetCurTime(theTime);
oldMode := SetBkMode(aDC, Transparent);
DrawText(aDC, theTime, strlen(theTime), Rect, dt_WordBreak);
FreeMem(theTime, StrLen(theTime) + 1);
SetBkMode(aDC, oldMode);
end;
procedure TGaugeDialog.DrawDate(aDC : HDC; Rect : TRect);
var
theDate : PChar;
oldMode : Integer;
begin
GetCurDate(theDate);
oldMode := SetBkMode(aDC, Transparent);
DrawText(aDC, theDate, strlen(theDate), Rect, dt_WordBreak);
FreeMem(theDate, StrLen(theDate) + 1);
SetBkMode(aDC, oldMode);
end;
procedure TGaugeDialog.IconPaint(aDC : HDC);
var
theRect : TRect;
oldBrush : HBrush;
begin
GetClientRect(HWindow, theRect);
oldBrush := SelectObject(aDC, whiteBrush);
with theRect do
Rectangle(aDC, left, top, right, bottom);
SelectObject(aDC, oldBrush);
case curChoice of
idr_DSpace : DrawDrive(aDC, theRect);
idr_Memory : DrawMemory(aDC, theRect);
idr_SysRes : DrawSysRes(aDC, theRect);
idr_Time : DrawTime(aDC, theRect);
idr_Date : DrawDate(aDC, theRect);
end;
end;
procedure TGaugeDialog.InitControls;
begin
sfSpace := New(PStatic, InitResource(@Self, ids_FSpace, 20));
stSpace := New(PStatic, InitResource(@Self, ids_TSpace, 20));
sfMemory := New(PStatic, InitResource(@Self, ids_FMem, 10));
sfRes := New(PStatic, InitResource(@Self, ids_FRes, 25));
sfTime := New(PStatic, InitResource(@Self, ids_Time, 15));
sfDate := New(PStatic, InitResource(@Self, ids_Date, 15));
lbDrives := New(PListBox, InitResource(@Self, idc_Drives));
rbDSpace := New(PRadioButton, InitResource(@Self, idr_DSpace));
rbMemory := New(PRadioButton, InitResource(@Self, idr_Memory));
rbSysRes := New(PRadioButton, InitResource(@Self, idr_SysRes));
rbTime := New(PRadioButton, InitResource(@Self, idr_Time));
rbDate := New(PRadioButton, InitResource(@Self, idr_Date));
end;
procedure TGaugeDialog.CMAbout(var Msg : TMessage);
var
Dialog : TDialog;
begin
Dialog.Init(@Self, 'AboutBox');
Dialog.Execute;
Dialog.Done;
end;
procedure TGaugeDialog.WMSysCommand(var Msg : TMessage);
begin
if Msg.WParam = cm_About then
CMAbout(Msg)
else
DefWndProc(Msg);
end;
procedure TGaugeDialog.WMDestroy(var Msg : TMessage);
begin
KillTimer(HWindow, id_Timer);
TDlgWindow.WMDestroy(Msg);
end;
procedure TGaugeDialog.WMTimer(var Msg : TMessage);
var
theDC : HDC;
begin
if IsIconic(HWindow) then
InvalidateRect(HWindow, Nil, True)
else begin
theDC := GetDC(HWindow);
UpdateControls(theDC);
ReleaseDC(HWindow, theDC);
end;
end;
procedure TGaugeDialog.WMCtlClr(var Msg : TMessage);
begin
if (GetDlgCtrlID(Msg.LParamLo) = ids_FSpace) then
if (Msg.LParamHi = ctlcolor_Static) then begin
SetBkColor(Msg.WParam, RGB(255, 0, 0));
SetTextColor(Msg.WParam, RGB(255, 255, 255));
end;
end;
procedure TGaugeDialog.WMPaint(var Msg : TMessage);
var
PaintDC : HDC;
PS : TPaintStruct;
begin
PaintDC := BeginPaint(Msg.Receiver, PS);
if IsIconic(HWindow) then
begin
IconPaint(PaintDC)
end
else
UpdateControls(PaintDC);
EndPaint(Msg.Receiver, PS);
end;
procedure TGaugeDialog.idDSpace(var Msg : TMessage);
begin
rbDSpace^.Check;
rbMemory^.UnCheck;
rbSysRes^.UnCheck;
rbTime^.UnCheck;
rbDate^.UnCheck;
curChoice := idr_DSpace;
end;
procedure TGaugeDialog.idMemory(var Msg : TMessage);
begin
rbDSpace^.UnCheck;
rbMemory^.Check;
rbSysRes^.UnCheck;
rbTime^.UnCheck;
rbDate^.UnCheck;
curChoice := idr_Memory;
end;
procedure TGaugeDialog.idSysRes(var Msg : TMessage);
begin
rbDSpace^.UnCheck;
rbMemory^.UnCheck;
rbSysRes^.Check;
rbTime^.UnCheck;
rbDate^.UnCheck;
curChoice := idr_SysRes;
end;
procedure TGaugeDialog.idTime(var Msg : TMessage);
begin
rbDSpace^.UnCheck;
rbMemory^.UnCheck;
rbSysRes^.UnCheck;
rbTime^.Check;
rbDate^.UnCheck;
curChoice := idr_Time;
end;
procedure TGaugeDialog.idDate(var Msg : TMessage);
begin
rbDSpace^.UnCheck;
rbMemory^.UnCheck;
rbSysRes^.UnCheck;
rbTime^.UnCheck;
rbDate^.Check;
curChoice := idr_Date;
end;
procedure TGaugeApp.InitMainWindow;
var
aMenu : HMenu;
begin
MainWindow := New(PGaugeDialog, Init(Nil, AppName));
end;
var
MyApp : TGaugeApp;
begin
MyApp.Init(AppName);
MyApp.Run;
MyApp.Done;
end.